<?php
class User_ForgotController extends Zend_Controller_Action{
	public function init(){
	$this->_helper->layout()->setLayout('register_login');
	}
	public function indexAction(){
		session_start();
		$this->view->imgcaptcha = ROOT.'application/modules/captcha/captcha.php';
	}

	public function forgotxulyAction(){
		session_start();
		$this->_helper->viewRenderer->setNoRender(true);
		$this->_helper->layout->disableLayout();

		if($_POST['captcha'] != $_SESSION['macaptcha']){
			echo'Capcha chua dung';
		}else{
			echo 'Capcha dung'; exit;
			include ('sendmail/class.phpmailer.php');
			include ('sendmail/class.smtp.php');
			$this->getHelper('viewRenderer')->setNoRender();
			$user_email = $_POST['user_email'];

			$user = new User_Model_DbTable_Users();
			$iduser = $user ->checkemail($user_email);
			if($iduser==0)
			{
				echo 'Email không tồn tại';
				exit;
			}
			else
			{
				$checkrshash = $user ->updateUserhash($iduser);
				echo $checkrshash;
				if(isset($checkrshash))
				{
					$mail = new PHPMailer();
					$mail->IsSMTP(); // set mailer to use SMTP
					$mail->Host = "smtp.gmail.com"; // specify main and backup server
					$mail->Port = 465; // set the port to use
					$mail->SMTPAuth = true; // turn on SMTP authentication
					$mail->SMTPSecure = 'ssl';
					$mail->Username = "info@ishali.com.vn"; // your SMTP username or your gmail username
					$mail->Password = "ishali.com.vn"; // your SMTP password or your gmail password
					$from = "info@ishali.com.vn"; // Reply to this email
					$to="hongtien510@ishali.com.vn"; // Recipients email ID
					$name="CTY TTQC ISHALI"; // Recipient's name
					$mail->From = $from;
					$mail->FromName = "CTY TTQC ISHALI"; // Name to indicate where the email came from when the recepient received
					$mail->AddAddress($to,$name);
					$mail->AddReplyTo($from,"CTY ISHALI");
					$mail->WordWrap = 50; // set word wrap
					$mail->IsHTML(true); // send as HTML
					$mail->Subject = "Test mail 2";
					$mail->Body = "test noi dung 2"; //HTML Body
					$mail->AltBody = "noi dung"; //Text Body
					//$mail->SMTPDebug = 2;
					if(!$mail->Send())
					{
						echo "<h1>Loi khi goi mail: " . $mail->ErrorInfo . '</h1>';
					}
					else
					{
						echo "<h1>Send mail thanh cong</h1>";
					}
				}
			}
		}
	
	}
	
}